<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>上传附件列表</title>
<link rel="stylesheet" href="<%=basePath %>/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="<%=basePath %>/plugins/bootstraptable/bootstrap-table.css">
    <link rel="stylesheet" href="<%=basePath %>/bootstrap/css/custom-theme/jquery-ui-1.9.2.custom.css">
    <link rel="stylesheet" href="<%=basePath%>/bootstrap/css/bootstrap-multiselect.css">
    
    
    <script src="<%=basePath %>/js/jquery.min.js"></script>
	<script src="<%=basePath %>/bootstrap/js/bootstrap.min.js"></script>
	<script src="<%=basePath %>/bootstrap/js/bootstrapQ.js"></script>
	<script src="<%=basePath %>/plugins/bootstraptable/bootstrap-table.js"></script>
	<script src="<%=basePath %>/plugins/bootstraptable/locale/bootstrap-table-zh-CN.js"></script>
	
	<script src="<%=basePath %>/plugins/bootstrapValidator/js/bootstrapValidator.min.js"></script>
	<script src="<%=basePath %>/plugins/bootstrapValidator/js/language/zh_CN.js"></script>
	<script src="<%=basePath%>/bootstrap/js/bootstrap-multiselect.js"></script>
	<script src="<%=basePath %>/js/util.js"></script>
    <script src="<%=basePath %>/plugins/layer/layer.js"></script>
	
	<link rel="stylesheet" href="<%=basePath%>/css/toastr.min.css">
	<script src="<%=basePath%>/js/toastr.min.js"></script>
	<script src="<%=basePath%>/js/toastrinit.js"></script>
<style> 
.table-hover>tbody>tr:hover{background-color:#C6E2FF}
</style>

<script type="text/javascript">
$(document).ready(function(){
	//控件初始化
    //控件初始化完毕
	
	//在表中显示数据
    var url = '<%=basePath %>/fileAdmin/pageFile.do';
    $("#table").bootstrapTable({
    		/*数据参数清单*/
            method:'post',//请求方式
            url:url,//请求url
            dataType:'json',
            queryParams:queryParams,//传递参数
            contentType:'application/x-www-form-urlencoded',//请求数据内容格式
            /*样式参数清单*/ 
            //分页参数
            pagination:true,//是否分页
        	pageList: [10, 25, 50, 100],
			pageSize:10,
			pageNumber:1,
			sidePagination:'server',
            showRefresh: true,//是否显示刷新按钮
            striped:true,//行间隔色
            locale:"${language}" ,
            toolbar:"#toolbar",
            clickToSelect:true,
            onClickRow: function (row,$element) {
           	   $element.addClass('info').siblings().removeClass('info').end();
           	}
       });
    //在初始化和查询要传递的参数
    function queryParams(params){	
        return {
        	fileName:$("#query_fileName").val(),
        	limit : params.limit ,
			offset : params.offset
        };
    };
    
   
    //查询按钮的点击事件
    $("#btn_query").click(function(){
        $("#table").bootstrapTable('refresh');
    });

    //添加
    $("#btn_add").click(function(){
    	layer.open({
			  id:'file_admin_add',
			  type: 2,
			  title:"<spring:message code='file.add' />",
			  area: ['70%', '90%'],
			  content: '<%=basePath %>/fileAdmin/toFileAddPage.do'
		});
    });
   
});//document结束

function orderFormatter(value,row,index){
	return index+1;
}


//字典状态显示
function dictionary_status_formatter(value, row, index) {
	if(row.status=='1'){
		return '<span class="text-success"> <spring:message code='base.normal' /> </span>';
	}
	if(row.status=='0'){
		return '<span class="text-danger">  <spring:message code='base.disable' /> </span>';
	}
	else{
		return '<span class="text-danger"><spring:message code='base.wrong' /></span>';
	}
};




//文件下载按钮
function operateFormatter(value, row, index) {
	return [
	    '<a target="_blank" class="download ml10" href="<%=basePath%>/file/download.do?id='+ row.fastdfsFilesId +'" title="<spring:message code='base.download' />">',
	        '<span class="glyphicon glyphicon-download-alt "  style="font-size:15px;"></span>',
	    '</a>',
	    '&nbsp;&nbsp;&nbsp;&nbsp;',
	    '<a class="delete_logic ml10" href="javascript:void(0)" title=" <spring:message code='base.delete.logic' /> ">',
        	'<span class="glyphicon glyphicon-remove"  style="font-size:15px;"></span>',
    	'</a>',
    	'&nbsp;&nbsp;&nbsp;&nbsp;',
    	'<a class="delete_true ml10" href="javascript:void(0)" title="<spring:message code='base.delete.true' />">',
        	'<span class="glyphicon glyphicon-exclamation-sign text-danger"  style="font-size:15px;"></span>',
        '</a>',
	].join('');
}

//操作功能
window.operateEvents = {
	//角色操作
	'click a.delete_logic': function (e, value, row, index) {
		$.ajax({
             type: "POST",
             dataType:"json",
             url: "<%=basePath %>/file/deleteLogic.do",
             data: {id:row.fastdfsFilesId},
             success: function(data){
	           if(data.msg=="success"){
	        	   toastr.success("<spring:message code='base.success' />");
	        	   $("#table").bootstrapTable('refresh');
	           }else{
	        		 toastr.error("<spring:message code='base.error' />");
	           }
             },error:function(data){
            	 toastr.error("<spring:message code='base.error' />");
             }
         });
	 } 
	 ,
	 'click a.delete_true': function (e, value, row, index) {
			$.ajax({
	             type: "POST",
	             dataType:"json",
	             url: "<%=basePath %>/file/deleteTrue.do",
	             data: {id:row.fastdfsFilesId},
	             success: function(data){	
		           if(data.msg=="success"){
		        	   toastr.success("<spring:message code='base.success' />");
		        	   $("#table").bootstrapTable('refresh');
		           }else{
		        		 toastr.error("<spring:message code='base.error' />");
		           }
	             },error:function(data){
	            	 toastr.error("<spring:message code='base.error' />");
	             }
	         });
		 } 
} ;
</script>

</head>
<body >
<div>
    <div style="float:left;width:98%; margin-left:1%">
            <div id="toolbar">
                    <div class="form-inline" >
                    <form id="queryForm">
                        <div class="form-group">
                            <div  style="vertical-align:top ">
                                <input  type="text" id="query_fileName"  class="" placeholder="<spring:message code='file.filename' />" > 
                            </div>
                        </div>
                        
                        <button id="btn_query" 	type="button" class="btn btn-primary"><spring:message code='base.search' /></button>
                        <button id="btn_add" 	type="button" class="btn btn-primary"><spring:message code='base.add' /></button>

					</form>
                    </div>
            </div>
            <table   id="table" class="table table-hover" >		  		    
                <thead>
                    <tr class="success"> 
                    	<th data-radio="true">i</th>
                        <th data-field="fileName"><spring:message code='file.filename' /></th>
                        <th data-field="fileKb"  >KB</th> 
                        <th data-field="createTime"  ><spring:message code='file.createtime' /></th>
                        <th data-field="createBy"  ><spring:message code='file.createby' /></th> 
                 	    <th data-field="type"  ><spring:message code='file.type' /></th> 
                 	    <th data-field="typeKey"  ><spring:message code='file.typekey' /></th> 
                        <th data-formatter="operateFormatter" data-events="operateEvents"><spring:message code='base.operate' /></th>
                    </tr>
                </thead>             
            </table>
    	</div> 
	</div> 
</body>
</html>